//
//  ModifyPasswordSaveController.m
//  tuanGG
//
//  Created by 微他 on 15/9/29.
//  Copyright (c) 2015年 weita. All rights reserved.
//

#import "ModifyPasswordSaveController.h"

@interface ModifyPasswordSaveController ()
@property (nonatomic,strong)UITextField *niePsw;
@property (nonatomic,strong)UITextField *pswTxt;
@end

@implementation ModifyPasswordSaveController
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = NO;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = RGBACOLOR(236, 235, 232, 1);
    [self addnavigationTitle:@"修改密码" navColor:@"4fd2be"];
    [self initView];
}
- (void)initView {

    UIView * loginView = [[UIView alloc]initWithFrame:CGRectMake(15,20, ScreenWidth - 30, 90)];
    [loginView.layer setCornerRadius:5.0];
    loginView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:loginView];

    //新密码
    _niePsw = [[UITextField alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth - 30, 45)];
    _niePsw.placeholder = @"请输入新密码";
    _niePsw.clearButtonMode = UITextFieldViewModeWhileEditing;
    _niePsw.font = BOLD_FONT(12);
    _niePsw.secureTextEntry = YES;
    _niePsw.keyboardType = UIKeyboardTypeNumberPad;
    [loginView addSubview:_niePsw];


    UIView *phoneleftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 35, 45)];
    [self.view addSubview:phoneleftView];
    UIImageView * phoneleft = [[UIImageView alloc]initWithFrame:CGRectMake(10, 13.5*PRO, 17, 18)];
    phoneleft.image = [UIImage imageNamed:@"AcountLeftimage.png"];
    [phoneleftView addSubview:phoneleft];
    _niePsw.leftViewMode = UITextFieldViewModeAlways;
    _niePsw.leftView = phoneleftView;

    //确认密码
    _pswTxt = [[UITextField alloc]initWithFrame:CGRectMake(0, 45, ScreenWidth - 30, 45)];
    _pswTxt.placeholder = @"确认密码";
    _pswTxt.clearButtonMode = UITextFieldViewModeWhileEditing;
    _pswTxt.font = BOLD_FONT(12);
    _pswTxt.secureTextEntry = YES;
    [loginView addSubview:_pswTxt];


    UIView *line = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 35, 45)];
    UIImageView *pswleft = [[UIImageView alloc]initWithFrame:CGRectMake(10, 12*PRO, 15, 19)];
    pswleft.image = [UIImage imageNamed:@"authCodeLeftimage.png"];
    [line addSubview:pswleft];
    _pswTxt.leftViewMode = UITextFieldViewModeAlways;
    _pswTxt.leftView = line;


    //分割线
    UIView * lineView = [[UIView alloc ]initWithFrame:CGRectMake(0, 45, ScreenWidth-30, 0.6)];
    lineView.backgroundColor = [UIColor colorWithHexString:@"c8c8c8" alpha:0.5];
    [loginView addSubview:lineView];


    UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(15, CGRectGetMaxY(loginView.frame)+50, ScreenWidth-30, 40)];
    button.backgroundColor = [UIColor colorWithHexString:@"4fd2be"];
    [button setTitle:@"确认" forState:UIControlStateNormal];
    button.layer.cornerRadius = 5;
    [button addTarget:self action:@selector(button) forControlEvents:UIControlEventTouchUpInside];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.view addSubview:button];
}

- (void)button  {
    if (_niePsw.text.length < 6 || _pswTxt.text.length < 6) {
        [Common addAlert:@"请输入不小于6位数的密码"];
    }else if(![_niePsw.text isEqualToString:_pswTxt.text]){
        [Common addAlert:@"前后密码不一致"];
    }else {
        [self Networking];
    }
}
- (void)Networking {
    NSDictionary *dictionary = @{@"tel":_phoneNumber,@"psw":_niePsw.text};
    [GLAFRequest startRequest:alteCenterPsw_url paramsDic:dictionary defaultdialog:YES ispost:YES handleSuccess:^(id sta, NSDictionary *paramsDic) {
        NSLog(@"%@",sta);
        if ([sta[@"code"]integerValue] == 1) {
            [Common addAlert:@"修改密码成功"];
            [self.navigationController popToRootViewControllerAnimated:YES];
        }
    } doFinally:^(NSDictionary *paramsDic) {

    }];
}
@end
